/*
    Copyright 2010 Barnet Wagman

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 */

package com.norbl.util;

/**
 *
 * @author Barnet Wagman
 */
public class TaskInProgressWindow 
    extends javax.swing.JFrame implements Runnable {

    String frameTitle;
    String headline;
    String message;

    /** Creates new form WaitWindow */
    public TaskInProgressWindow(String frameTitle,String headline,String message) {
        this.frameTitle = frameTitle;
        this.headline = headline;
        this.message = message;
    }
    
    public void run() {
        initComponents();
        setTitle(frameTitle);
        GuiUtil.setNBLIcon(this);
        GuiUtil.centerOnScreen(this);
        setVisible(true);
    }

    public static TaskInProgressWindow run(String frameTitle,
                                           String headline,
                                           String message) {
        TaskInProgressWindow tip = new TaskInProgressWindow(frameTitle,
                                                            headline,
                                                            message);
        java.awt.EventQueue.invokeLater(tip);
        return(tip);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        headlineLabel = new javax.swing.JLabel();
        messageLabel = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        headlineLabel.setFont(new java.awt.Font("DejaVu Sans", 1, 16)); // NOI18N
        headlineLabel.setText("jLabel1");
        headlineLabel.setText(headline);

        messageLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 12)); // NOI18N
        messageLabel.setText("jLabel2");
        messageLabel.setText(message);

        jProgressBar1.setIndeterminate(true);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(headlineLabel)
                    .addComponent(messageLabel)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(33, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(headlineLabel)
                .addGap(35, 35, 35)
                .addComponent(messageLabel)
                .addGap(80, 80, 80)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {

        TaskInProgressWindow tip =
            TaskInProgressWindow.run("In progress",
                                     "RunJRun",
                                     "<html>XXX is running" +
                "<br>running running</html>");
        com.norbl.util.Time.nap(20L * 1000L);
        tip.dispose();


//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new TaskInProgressWindow("<html>XXX is running" +
//            "<br>"   +
//            " running  running</html>"
//                        ).setVisible(true);
//            }
//        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel headlineLabel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JLabel messageLabel;
    // End of variables declaration//GEN-END:variables

}
